// pages/Settlement/Statistics/Statistics.js

const controllers = require('../../controllers/controllerIndex.js').controller;
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    totalIncome:0,
    totalPay:0,
    isPickerRender: false,
    isPickerShow: false,
    startTime: "2019-01-01",
    endTime: "2019-12-01",
    keywork:"",
    pickerConfig: {
      endDate: true,
      column: "",
      dateLimit: false,
      initStartTime: "2019-01-01",
      initEndTime: "2019-12-01",
      limitStartTime: "2015-05-06 ",
      limitEndTime: "2055-05-06"
    },
  },
  bindPickerChange: function(e) {
    console.log("picker发送选择改变，携带值为", e.detail.value);
    console.log(this.data.sensorList);

    this.getData(this.data.sensorList[e.detail.value].id);
    // let startDate = util.formatTime(new Date(new Date().getTime() - 24 * 60 * 60 * 1000 * 7));
    // let endDate = util.formatTime(new Date());
    this.setData({
      index: e.detail.value,
      sensorId: this.data.sensorList[e.detail.value].id
      // startDate,
      // endDate
    });
  },
  setPickerTime: function(val) {
    console.log(val);
    let data = val.detail;
    let startTime=/\d{4}-\d{1,2}-\d{1,2}/g.exec(data.startTime)
    let endTime=/\d{4}-\d{1,2}-\d{1,2}/g.exec(data.endTime)
    this.setData({
      startTime: startTime,
      endTime:endTime
    });
  }, pickerShow: function() {
    this.setData({
      isPickerShow: true,
      isPickerRender: true,
      chartHide: true
    });
  },
  pickerHide: function() {
    this.setData({
      isPickerShow: false,
      chartHide: false
    });
  },

  getofflineBusiness(){
    let params={
      sessionId: wx.getStorageSync('token'),
      shopId:wx.getStorageSync('shopId'),
     
        startTime:  this.data.startTime,
        endTime : this.data.endTime,
       
    }
    controllers.offlineBusiness(
      params
    ).then(res =>{
      console.log(res);
  
      this.setData({
        accountOrderNum:res.data.accountOrderNum,
        vipOrderNum:res.data.vipOrderNum ,
        accountOrderMoney:res.data.accountOrderMoney,
        vipOrderMoney:res.data.vipOrderMoney
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let params={
      sessionId: wx.getStorageSync('token'),
      shopId:wx.getStorageSync('shopId'),
    
    }
    let newTime=new Date();
     this.setData({
    endTime: newTime.getFullYear()+'-'+  (newTime.getMonth()+1)+'-'+ newTime.getDate(),
    'pickerConfig.initEndTime':newTime.getFullYear()+'-'+  (newTime.getMonth()+1)+'-'+ newTime.getDate()
   })
    controllers.totalOfflineBusiness(
      params
    ).then(res =>{
      console.log(res);
      this.setData({
        totalIncome:res.data.totalIncome,
        totalPay:res.data.totalPay
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
   // onShareAppMessage: function () {

  // }
})